<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>设置我的资料</title>
<meta name="renderer" content="webkit">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport"
	content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
	<script th:src="@{/js/includ.js}"></script>
</head>
<body>
	<div class="layui-fluid">
		<div class="layui-row layui-col-space15">
			<div class="layui-col-md12">
				<div class="layui-card">
					<div class="layui-card-header">设置我的资料</div>
					<div class="layui-card-body" pad15>
						<input id="employeeId" type="hidden" name="employeeId"
							th:value="${employee.employeeId }" />
						<div class="layui-form" lay-filter="">
							<div class="layui-form-item">
								<label class="layui-form-label">我的角色</label>
								<div class="layui-input-inline">
									<select name="role" lay-verify="">
										<option value="1" selected>[[${employee.role.roleName}]]</option>
									</select>
								</div>
								<div class="layui-form-mid layui-word-aux">当前角色不可更改为其它角色</div>
							</div>
							<div class="layui-form-item">
								<label class="layui-form-label">用户登录名</label>
								<div class="layui-input-inline">
									<input type="text" name="employeeLoginName"
										th:value="${employee.employeeLoginName}" readonly="readonly"
										class="layui-input">
								</div>
								<div class="layui-form-mid layui-word-aux">后台登入名不能修改</div>
							</div>
							<div class="layui-form-item">
								<label class="layui-form-label">昵称</label>
								<div class="layui-input-inline">
									<input type="text" id="employeeNickName"
										name="employeeNickName" th:value="${employee.employeeNickName}"
										lay-verify="nickname" autocomplete="off" placeholder="请输入昵称"
										class="layui-input">
								</div>
							</div>
							<div class="layui-form-item">
								<label class="layui-form-label">真实名称</label>
								<div class="layui-input-inline">
									<input type="text" id="employeeName"
										name="employeeInfo.employeeName"
										th:value="${employee.employeeInfo.employeeName}"
										lay-verify="nickname" autocomplete="off" placeholder="填写实名"
										class="layui-input">
								</div>
							</div>
							<div class="layui-form-item">
								<label class="layui-form-label">性别</label>
								<div class="layui-input-block">
									<input type="radio" name="employeeInfo.employeeSex" value="女"
										title="女"
										th:checked="${employee.employeeInfo.employeeSex=='女' }" />
									<input type="radio" name="employeeInfo.employeeSex" value="男"
										title="男"
										th:checked="${employee.employeeInfo.employeeSex=='男' }" />
									<input type="radio" name="employeeInfo.employeeSex" value="未知"
										title="未知"
										th:checked="${employee.employeeInfo.employeeSex=='未知' }" />
								</div>
							</div>
							<div class="layui-form-item">
								<label class="layui-form-label">手机</label>
								<div class="layui-input-inline">
									<input type="text" id="employeePhone"
										name="employeeInfo.employeePhone"
										th:value="${employee.employeeInfo.employeePhone }"
										lay-verify="phone" autocomplete="off" class="layui-input">
								</div>
							</div>
							<div class="layui-form-item">
								<label class="layui-form-label">邮箱</label>
								<div class="layui-input-inline">
									<input type="text" id="employeeEmail"
										name="employeeInfo.employeeEmail"
										th:value="${employee.employeeInfo.employeeEmail }"
										lay-verify="email" autocomplete="off" class="layui-input">
								</div>
							</div>
							<div class="layui-form-item">
								<label class="layui-form-label">通讯地址</label>
								<div class="layui-input-inline">
									<input type="text" id="employeeAddr"
										name="employeeInfo.employeeAddr"
										th:value="${employee.employeeInfo.employeeAddr }"
										lay-verify="email" autocomplete="off" class="layui-input">
								</div>
							</div>
							<div class="layui-form-item">
								<div class="layui-input-block">
									<button class="layui-btn" id="setmyinfo">确认修改</button>
									<button type="reset" class="layui-btn layui-btn-primary">重新填写</button>
								</div>
							</div>
						</div>

					</div>
				</div>
			</div>
		</div>
	</div>
	<script>
		var data = {};
		layui.config({
			base : webRoot+'/layuiadmin/' //静态资源所在路径
		}).extend({
			index : 'lib/index' //主入口模块
		}).use([ 'index', 'set' ], function() {
			var $ = layui.$;
			$('#setmyinfo').click(function() {
				if (checkedSubmit()) {
					$.ajax({
						url : webRoot+'/user/personalData',
						data : JSON.stringify(data),
						type : 'POST',
						contentType: 'application/json',
						dataType : 'json',
						success : function(res) {
							if (res.result_code && res.return_code) {
								toastSuccessMsgANDRelonin('修改成功，重新登录',webRoot+'/loginOut');
							} else {
								toast('修改失败');
							}
						}
					});
				}
			});
			function checkedSubmit() {
				let employeeNickName = $.trim($('#employeeNickName').val());
				let employeeName = $.trim($('#employeeName').val());
				let employeeSex = $("input[type='radio']:checked").val();
				let employeePhone = $.trim($('#employeePhone').val());
				let employeeEmail = $.trim($('#employeeEmail').val());
				let employeeAddr = $.trim($('#employeeAddr').val());
				if (employeeNickName == '') {
					toast('昵称不能为空');
					return false;
				}
				let employeeInfo = {};
				if (employeeName != '') {
					employeeInfo.employeeName = employeeName;
				}
				if (employeePhone != '') {
					if (!checkPhone(employeePhone)) {
						toast('请输入正确的手机号');
						return false;
					}
					employeeInfo.employeePhone = employeePhone;
				}

				if (employeeEmail != '') {
					if (!checkEmail(employeeEmail)) {
						toast('邮箱格式不正确');
						return false;
					}
					employeeInfo.employeeEmail = employeeEmail;
				}
				if (employeeAddr != '') {
					employeeInfo.employeeAddr = employeeAddr;
				}
				let employeeId = $('#employeeId').val();
				data.employeeId = employeeId;
				data.employeeNickName = employeeNickName;
				employeeInfo.employeeId = employeeId;
				employeeInfo.employeeSex = employeeSex;
				data.employeeInfo = employeeInfo;
				return true;
			}
		});
		
	</script>
</body>
</html>